package practise.alogrithm.hundredInterviewQuestions;

import practise.alogrithm.hundredInterviewQuestions.Utils.TreeBuilder;
import practise.alogrithm.hundredInterviewQuestions.Utils.TreeNode;

/**
 * Created by richard on 6/3/14.
 */
public class GetTreeDepth {
    public static int getDepth(TreeNode treeNode){
        if(treeNode.getLeft()==null&&treeNode.getRight()==null){
            return 1;
        }
        if(treeNode==null){
            return 0;
        }
        return Math.max(getDepth(treeNode.getLeft()),getDepth(treeNode.getRight()))+1;
    }

    public static void main(String[] args){
        System.out.print("Result:"+getDepth(TreeBuilder.createTreeByArrayInWidth(new int[]{10,6,14,4,0,12,16})));
    }
}
